package symbolrt.manager;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import symbolrt.synthesis.SynthesisUnit;
import symbolrt.translation.parser.TranslationUnit;

/**
 * <code>DataManager</code> Class. <br>
 * 
 * This class delegates all tasks and required data for each component of the
 * system.
 * 
 * @author Jeanderson Barros Candido ( <a
 *         href="mailto:jeandersonbc@gmail.com">jeandersonbc@gmail.com</a> )
 * 
 * @version 1.0 <br>
 *          (C) Copyright 2012 SYMBOL-RT Translator.
 */
public class DataManager {

	/**
	 * Usage message
	 */
	public static final String USAGE = "Usage: java -jar symbolrt.jar filePath [specificationName] [testPurposeName]";
	/**
	 * Error message
	 */
	public static final String PARAMS_MSG = "SyMBolRT: No specification and test purpose names were defined";

	/**
	 * @param args
	 *            An array containing file path, specification name and test
	 *            purpose name (in this order)
	 */
	public static void start(String[] args) {
		String specificationName = null;
		String testPurposeName = null;
		String filePath = null;

		if (args != null && args.length > 0) {
			filePath = args[0];
			createFile(filePath);
			if (args.length == 3) {
				specificationName = args[1];
				testPurposeName = args[2];
				SynthesisUnit.setUp(specificationName, testPurposeName);
				SynthesisUnit.init();

			} else {
				System.out.println(PARAMS_MSG);
				System.out.println(USAGE);
			}

		} else {
			System.out.println(USAGE);
		}
		System.out.println("Finished");
	}

	/**
	 * Instantiates a file for the given source-code
	 * 
	 * @param filePath
	 *            The path of the source-code
	 */
	private static void createFile(String filePath) {
		BufferedInputStream file = null;
		try {
			file = new BufferedInputStream(new FileInputStream(new File(
					filePath)));
			TranslationUnit.init(file);

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
